//
// Created by mac on 2/22/22.
//

#include <vector>
using namespace std;

vector<int> searchRange(vector<int>& nums, int target) {
    vector<int> res(2, -1);

    int left = 0;
    int right = nums.size()-1;

    while (left<=right){
        int mid = left + (right - left)/2;
        if(nums[mid]==target){
            int first = mid;
            int second = mid;

            while (first-1>=0 && nums[first-1]==target){
                first--;
            }

            while (second+1<nums.size() && nums[second+1]==target){
                second++;
            }
            res[0] = first;
            res[1] = second;
            return res;
        } else if(nums[mid]<target){
            left = mid+1;
        } else{
            right = mid-1;
        }

    }
    return res;


}
